<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="./js/coder_app.js"></script>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="./rtwreport_utils.js"></script>
<script type="text/javascript" src="./rtwannotate.js"></script>
<link rel="stylesheet" type="text/css" href="./css/coder_app.css"/>
</head>
<body onload="srcFileOnload();">
<pre id="code">
<table class="code" id="codeTbl">
<tr name="1" id="1">
<td><a id="l1" class='ln'>1</a></td><td><span class="ct">/*</span></td></tr>
<tr name="2" id="2">
<td><a id="l2" class='ln'>2</a></td><td><span class="ct"> * Code generated for Simulink model VCUComposition_demo.</span></td></tr>
<tr name="3" id="3">
<td><a id="l3" class='ln'>3</a></td><td><span class="ct"> *</span></td></tr>
<tr name="4" id="4">
<td><a id="l4" class='ln'>4</a></td><td><span class="ct"> * FILE    : cpu.c</span></td></tr>
<tr name="5" id="5">
<td><a id="l5" class='ln'>5</a></td><td><span class="ct"> *</span></td></tr>
<tr name="6" id="6">
<td><a id="l6" class='ln'>6</a></td><td><span class="ct"> * VERSION : 1.86</span></td></tr>
<tr name="7" id="7">
<td><a id="l7" class='ln'>7</a></td><td><span class="ct"> *</span></td></tr>
<tr name="8" id="8">
<td><a id="l8" class='ln'>8</a></td><td><span class="ct"> * DATE    : Sun Sep  8 01:03:14 2024</span></td></tr>
<tr name="9" id="9">
<td><a id="l9" class='ln'>9</a></td><td><span class="ct"> *</span></td></tr>
<tr name="10" id="10">
<td><a id="l10" class='ln'>10</a></td><td><span class="ct"> * Copyright 2011-2017 ECUCoder. All Rights Reserved.</span></td></tr>
<tr name="11" id="11">
<td><a id="l11" class='ln'>11</a></td><td><span class="ct"> */</span></td></tr>
<tr name="12" id="12">
<td><a id="l12" class='ln'>12</a></td><td></td></tr>
<tr name="13" id="13">
<td><a id="l13" class='ln'>13</a></td><td><span class="pp">#include "cpu.h"</span></td></tr>
<tr name="14" id="14">
<td><a id="l14" class='ln'>14</a></td><td></td></tr>
<tr name="15" id="15">
<td><a id="l15" class='ln'>15</a></td><td><span class="ct">/**************************************************************************</span></td></tr>
<tr name="16" id="16">
<td><a id="l16" class='ln'>16</a></td><td><span class="ct"> * FUNCTION :    ec_cpu_init                                               *</span></td></tr>
<tr name="17" id="17">
<td><a id="l17" class='ln'>17</a></td><td><span class="ct"> *                                                                         *</span></td></tr>
<tr name="18" id="18">
<td><a id="l18" class='ln'>18</a></td><td><span class="ct"> * DESCRIPTION : Initialize the CPU module                                 *</span></td></tr>
<tr name="19" id="19">
<td><a id="l19" class='ln'>19</a></td><td><span class="ct"> *                                                                         *</span></td></tr>
<tr name="20" id="20">
<td><a id="l20" class='ln'>20</a></td><td><span class="ct"> *                                                                         *</span></td></tr>
<tr name="21" id="21">
<td><a id="l21" class='ln'>21</a></td><td><span class="ct"> * PARAMETERS :  None                   *</span></td></tr>
<tr name="22" id="22">
<td><a id="l22" class='ln'>22</a></td><td><span class="ct"> *                                                                         *</span></td></tr>
<tr name="23" id="23">
<td><a id="l23" class='ln'>23</a></td><td><span class="ct"> * RETURN :      None                                                      *</span></td></tr>
<tr name="24" id="24">
<td><a id="l24" class='ln'>24</a></td><td><span class="ct"> ***************************************************************************/</span></td></tr>
<tr name="25" id="25">
<td><a id="l25" class='ln'>25</a></td><td><span class="kw">void</span> <a id="25c6" class="tk">ec_cpu_init</a>(<span class="kw">void</span>)</td></tr>
<tr name="26" id="26">
<td><a id="l26" class='ln'>26</a></td><td><span class="br">{</span></td></tr>
<tr name="27" id="27">
<td><a id="l27" class='ln'>27</a></td><td>  <span class="ct">//使能所有模式并开启所有外设，使能DRUN模式下外部时钟</span></td></tr>
<tr name="28" id="28">
<td><a id="l28" class='ln'>28</a></td><td>  <a id="28c3" class="tk">MC_ME</a>.<a id="28c9" class="tk">ME</a>.<a id="28c12" class="tk">R</a> = 0x000005FF;</td></tr>
<tr name="29" id="29">
<td><a id="l29" class='ln'>29</a></td><td>  <a id="29c3" class="tk">MC_ME</a>.<a id="29c9" class="tk">RUN_PC</a>[0].<a id="29c19" class="tk">R</a> = 0x000000FE;</td></tr>
<tr name="30" id="30">
<td><a id="l30" class='ln'>30</a></td><td>  <a id="30c3" class="tk">XOSC</a>.<a id="30c8" class="tk">CTL</a>.<a id="30c12" class="tk">B</a>.<a id="30c14" class="tk">OSCM</a> = 1;</td></tr>
<tr name="31" id="31">
<td><a id="l31" class='ln'>31</a></td><td>  <a id="31c3" class="tk">XOSC</a>.<a id="31c8" class="tk">CTL</a>.<a id="31c12" class="tk">B</a>.<a id="31c14" class="tk">EOCV</a> = 0x80;</td></tr>
<tr name="32" id="32">
<td><a id="l32" class='ln'>32</a></td><td>  <a id="32c3" class="tk">MC_ME</a>.<a id="32c9" class="tk">DRUN_MC</a>.<a id="32c17" class="tk">B</a>.<a id="32c19" class="tk">XOSCON</a> = 1;</td></tr>
<tr name="33" id="33">
<td><a id="l33" class='ln'>33</a></td><td>  <a id="33c3" class="tk">PMC</a>.<a id="33c7" class="tk">PMCCR</a>.<a id="33c13" class="tk">B</a>.<a id="33c15" class="tk">PMCCR_EN</a> = 1;</td></tr>
<tr name="34" id="34">
<td><a id="l34" class='ln'>34</a></td><td>  <a id="34c3" class="tk">PMC</a>.<a id="34c7" class="tk">PMCCR</a>.<a id="34c13" class="tk">B</a>.<a id="34c15" class="tk">INT_AUX_REG_BYPASS</a> = 0;</td></tr>
<tr name="35" id="35">
<td><a id="l35" class='ln'>35</a></td><td>  <a id="35c3" class="tk">PMC</a>.<a id="35c7" class="tk">PMCCR</a>.<a id="35c13" class="tk">B</a>.<a id="35c15" class="tk">PMCCR_EN</a> = 0;</td></tr>
<tr name="36" id="36">
<td><a id="l36" class='ln'>36</a></td><td></td></tr>
<tr name="37" id="37">
<td><a id="l37" class='ln'>37</a></td><td>  <span class="ct">//配置AC0，用于ADC，SGEN与MOTC，时钟源选择PLL0（160MHz）</span></td></tr>
<tr name="38" id="38">
<td><a id="l38" class='ln'>38</a></td><td>  <span class="ct">//进入ADC时钟10MHz，进入SGEN时钟20MHz，进入MOTC时钟20MHz</span></td></tr>
<tr name="39" id="39">
<td><a id="l39" class='ln'>39</a></td><td>  <a id="39c3" class="tk">MC_CGM_AC0_SC</a> = 0X02000000;</td></tr>
<tr name="40" id="40">
<td><a id="l40" class='ln'>40</a></td><td>  <a id="40c3" class="tk">MC_CGM</a>.<a id="40c10" class="tk">AC0_DC2</a>.<a id="40c18" class="tk">R</a> = 0x800F0000;</td></tr>
<tr name="41" id="41">
<td><a id="l41" class='ln'>41</a></td><td>  <a id="41c3" class="tk">MC_CGM</a>.<a id="41c10" class="tk">AC0_DC1</a>.<a id="41c18" class="tk">R</a> = 0x80070000;</td></tr>
<tr name="42" id="42">
<td><a id="l42" class='ln'>42</a></td><td>  <a id="42c3" class="tk">MC_CGM</a>.<a id="42c10" class="tk">AC0_DC0</a>.<a id="42c18" class="tk">R</a> = 0x80050000;</td></tr>
<tr name="43" id="43">
<td><a id="l43" class='ln'>43</a></td><td></td></tr>
<tr name="44" id="44">
<td><a id="l44" class='ln'>44</a></td><td>  <span class="ct">//配置SC，用于系统时钟，外设桥时钟</span></td></tr>
<tr name="45" id="45">
<td><a id="l45" class='ln'>45</a></td><td>  <span class="ct">//MC_CGM.SC_DC0.R = 0x00010000;</span></td></tr>
<tr name="46" id="46">
<td><a id="l46" class='ln'>46</a></td><td></td></tr>
<tr name="47" id="47">
<td><a id="l47" class='ln'>47</a></td><td>  <span class="ct">//配置PLL0与相关模块，XOSC晶振输入，160MHz</span></td></tr>
<tr name="48" id="48">
<td><a id="l48" class='ln'>48</a></td><td>  <a id="48c3" class="tk">MC_CGM_AC3_SC</a> = 0X01000000;</td></tr>
<tr name="49" id="49">
<td><a id="l49" class='ln'>49</a></td><td>  <a id="49c3" class="tk">PLLDIG</a>.<a id="49c10" class="tk">PLL0DV</a>.<a id="49c17" class="tk">B</a>.<a id="49c19" class="tk">PREDIV</a> = 4;</td></tr>
<tr name="50" id="50">
<td><a id="l50" class='ln'>50</a></td><td>  <a id="50c3" class="tk">PLLDIG</a>.<a id="50c10" class="tk">PLL0DV</a>.<a id="50c17" class="tk">B</a>.<a id="50c19" class="tk">RFDPHI1</a> = 1;</td></tr>
<tr name="51" id="51">
<td><a id="l51" class='ln'>51</a></td><td>  <a id="51c3" class="tk">PLLDIG</a>.<a id="51c10" class="tk">PLL0DV</a>.<a id="51c17" class="tk">B</a>.<a id="51c19" class="tk">MFD</a> = 12;</td></tr>
<tr name="52" id="52">
<td><a id="l52" class='ln'>52</a></td><td>  <a id="52c3" class="tk">PLLDIG</a>.<a id="52c10" class="tk">PLL0DV</a>.<a id="52c17" class="tk">B</a>.<a id="52c19" class="tk">RFDPHI</a> = 1;</td></tr>
<tr name="53" id="53">
<td><a id="l53" class='ln'>53</a></td><td></td></tr>
<tr name="54" id="54">
<td><a id="l54" class='ln'>54</a></td><td>  <span class="ct">//配置PLL1与相关模块，XOSC晶振输入，160MHz</span></td></tr>
<tr name="55" id="55">
<td><a id="l55" class='ln'>55</a></td><td>  <a id="55c3" class="tk">MC_CGM_AC4_SC</a> = 0X01000000;</td></tr>
<tr name="56" id="56">
<td><a id="l56" class='ln'>56</a></td><td>  <a id="56c3" class="tk">PLLDIG</a>.<a id="56c10" class="tk">PLL1DV</a>.<a id="56c17" class="tk">B</a>.<a id="56c19" class="tk">RFDPHI</a> = 2;</td></tr>
<tr name="57" id="57">
<td><a id="l57" class='ln'>57</a></td><td>  <a id="57c3" class="tk">PLLDIG</a>.<a id="57c10" class="tk">PLL1DV</a>.<a id="57c17" class="tk">B</a>.<a id="57c19" class="tk">MFD</a> = 12;</td></tr>
<tr name="58" id="58">
<td><a id="l58" class='ln'>58</a></td><td></td></tr>
<tr name="59" id="59">
<td><a id="l59" class='ln'>59</a></td><td>  <span class="ct">//打开XOSC,PLL0与PLL1</span></td></tr>
<tr name="60" id="60">
<td><a id="l60" class='ln'>60</a></td><td>  <a id="60c3" class="tk">MC_ME</a>.<a id="60c9" class="tk">DRUN_MC</a>.<a id="60c17" class="tk">B</a>.<a id="60c19" class="tk">XOSCON</a> = 1;</td></tr>
<tr name="61" id="61">
<td><a id="l61" class='ln'>61</a></td><td>  <a id="61c3" class="tk">MC_ME</a>.<a id="61c9" class="tk">DRUN_MC</a>.<a id="61c17" class="tk">B</a>.<a id="61c19" class="tk">PLL0ON</a> = 1;</td></tr>
<tr name="62" id="62">
<td><a id="l62" class='ln'>62</a></td><td>  <a id="62c3" class="tk">MC_ME</a>.<a id="62c9" class="tk">DRUN_MC</a>.<a id="62c17" class="tk">B</a>.<a id="62c19" class="tk">PLL1ON</a> = 1;</td></tr>
<tr name="63" id="63">
<td><a id="l63" class='ln'>63</a></td><td>  <a id="63c3" class="tk">MC_ME</a>.<a id="63c9" class="tk">DRUN_MC</a>.<a id="63c17" class="tk">B</a>.<a id="63c19" class="tk">SYSCLK</a> = 4;</td></tr>
<tr name="64" id="64">
<td><a id="l64" class='ln'>64</a></td><td>  <a id="64c3" class="tk">MC_ME</a>.<a id="64c9" class="tk">MCTL</a>.<a id="64c14" class="tk">R</a> = 0x30005AF0;</td></tr>
<tr name="65" id="65">
<td><a id="l65" class='ln'>65</a></td><td>  <a id="65c3" class="tk">MC_ME</a>.<a id="65c9" class="tk">MCTL</a>.<a id="65c14" class="tk">R</a> = 0x3000A50F;</td></tr>
<tr name="66" id="66">
<td><a id="l66" class='ln'>66</a></td><td></td></tr>
<tr name="67" id="67">
<td><a id="l67" class='ln'>67</a></td><td>  <span class="ct">//等待模式转换完成</span></td></tr>
<tr name="68" id="68">
<td><a id="l68" class='ln'>68</a></td><td>  <span class="kw">while</span> (<a id="68c10" class="tk">MC_ME</a>.<a id="68c16" class="tk">GS</a>.<a id="68c19" class="tk">B</a>.<a id="68c21" class="tk">S_MTRANS</a> <a id="68c30" class="tk">==</a> 1 ) ;</td></tr>
<tr name="69" id="69">
<td><a id="l69" class='ln'>69</a></td><td>  <span class="kw">while</span> (<a id="69c10" class="tk">MC_ME</a>.<a id="69c16" class="tk">GS</a>.<a id="69c19" class="tk">B</a>.<a id="69c21" class="tk">S_CURRENT_MODE</a> <a id="69c36" class="tk">!=</a> 0x3 ) ;</td></tr>
<tr name="70" id="70">
<td><a id="l70" class='ln'>70</a></td><td>  <span class="kw">while</span> (<a id="70c10" class="tk">MC_ME</a>.<a id="70c16" class="tk">GS</a>.<a id="70c19" class="tk">B</a>.<a id="70c21" class="tk">S_SYSCLK</a> <a id="70c30" class="tk">!=</a> 4 ) ;</td></tr>
<tr name="71" id="71">
<td><a id="l71" class='ln'>71</a></td><td><span class="br">}</span></td></tr>
<tr name="72" id="72">
<td><a id="l72" class='ln'>72</a></td><td></td></tr>
<tr name="73" id="73">
<td><a id="l73" class='ln'>73</a></td><td><span class="kw">void</span> <a id="73c6" class="tk">ec_cpu_lpme</a>(<span class="kw">void</span>)</td></tr>
<tr name="74" id="74">
<td><a id="l74" class='ln'>74</a></td><td><span class="br">{</span></td></tr>
<tr name="75" id="75">
<td><a id="l75" class='ln'>75</a></td><td>  <span class="ct">//打开XOSC,PLL0与PLL1</span></td></tr>
<tr name="76" id="76">
<td><a id="l76" class='ln'>76</a></td><td>  <a id="76c3" class="tk">MC_ME</a>.<a id="76c9" class="tk">DRUN_MC</a>.<a id="76c17" class="tk">B</a>.<a id="76c19" class="tk">XOSCON</a> = 1;</td></tr>
<tr name="77" id="77">
<td><a id="l77" class='ln'>77</a></td><td>  <a id="77c3" class="tk">MC_ME</a>.<a id="77c9" class="tk">DRUN_MC</a>.<a id="77c17" class="tk">B</a>.<a id="77c19" class="tk">PLL0ON</a> = 1;</td></tr>
<tr name="78" id="78">
<td><a id="l78" class='ln'>78</a></td><td>  <a id="78c3" class="tk">MC_ME</a>.<a id="78c9" class="tk">DRUN_MC</a>.<a id="78c17" class="tk">B</a>.<a id="78c19" class="tk">PLL1ON</a> = 1;</td></tr>
<tr name="79" id="79">
<td><a id="l79" class='ln'>79</a></td><td>  <a id="79c3" class="tk">MC_ME</a>.<a id="79c9" class="tk">DRUN_MC</a>.<a id="79c17" class="tk">B</a>.<a id="79c19" class="tk">SYSCLK</a> = 0;</td></tr>
<tr name="80" id="80">
<td><a id="l80" class='ln'>80</a></td><td>  <a id="80c3" class="tk">MC_ME</a>.<a id="80c9" class="tk">MCTL</a>.<a id="80c14" class="tk">R</a> = 0x30005AF0;</td></tr>
<tr name="81" id="81">
<td><a id="l81" class='ln'>81</a></td><td>  <a id="81c3" class="tk">MC_ME</a>.<a id="81c9" class="tk">MCTL</a>.<a id="81c14" class="tk">R</a> = 0x3000A50F;</td></tr>
<tr name="82" id="82">
<td><a id="l82" class='ln'>82</a></td><td></td></tr>
<tr name="83" id="83">
<td><a id="l83" class='ln'>83</a></td><td>  <span class="ct">//等待模式转换完成</span></td></tr>
<tr name="84" id="84">
<td><a id="l84" class='ln'>84</a></td><td>  <span class="kw">while</span> (<a id="84c10" class="tk">MC_ME</a>.<a id="84c16" class="tk">GS</a>.<a id="84c19" class="tk">B</a>.<a id="84c21" class="tk">S_MTRANS</a> <a id="84c30" class="tk">==</a> 1 ) ;</td></tr>
<tr name="85" id="85">
<td><a id="l85" class='ln'>85</a></td><td>  <span class="kw">while</span> (<a id="85c10" class="tk">MC_ME</a>.<a id="85c16" class="tk">GS</a>.<a id="85c19" class="tk">B</a>.<a id="85c21" class="tk">S_CURRENT_MODE</a> <a id="85c36" class="tk">!=</a> 0x3 ) ;</td></tr>
<tr name="86" id="86">
<td><a id="l86" class='ln'>86</a></td><td>  <span class="kw">while</span> (<a id="86c10" class="tk">MC_ME</a>.<a id="86c16" class="tk">GS</a>.<a id="86c19" class="tk">B</a>.<a id="86c21" class="tk">S_SYSCLK</a> <a id="86c30" class="tk">!=</a> 0 ) ;</td></tr>
<tr name="87" id="87">
<td><a id="l87" class='ln'>87</a></td><td><span class="br">}</span></td></tr>
<tr name="88" id="88">
<td><a id="l88" class='ln'>88</a></td><td></td></tr>
<tr name="89" id="89">
<td><a id="l89" class='ln'>89</a></td><td><span class="ct">/* File trailer for ECUCoder generated file cpu.c.</span></td></tr>
<tr name="90" id="90">
<td><a id="l90" class='ln'>90</a></td><td><span class="ct"> *</span></td></tr>
<tr name="91" id="91">
<td><a id="l91" class='ln'>91</a></td><td><span class="ct"> * [EOF]</span></td></tr>
<tr name="92" id="92">
<td><a id="l92" class='ln'>92</a></td><td><span class="ct"> */</span></td></tr>
<tr name="93" id="93">
<td><a id="l93" class='ln'>93</a></td><td></td></tr>
</table>
</pre>
</body>
</html>
